package com.weishu.house.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.weishu.house.entity.CwPaymentPlan;
import com.weishu.house.entity.SfContract;
import com.weishu.house.mapper.SfContractMapper;
import com.weishu.house.model.RequestSearchSfContractsDto;
import com.weishu.house.model.SfContractModel;
import com.weishu.house.service.ICwPaymentPlanService;
import com.weishu.house.model.RequestSearchSfsDto;
import com.weishu.house.model.ResponseHouseInfoDto;
import com.weishu.house.model.ResponseSearchSfsDto;
import com.weishu.house.service.ISfContractService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.*;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gao
 * @since 2021-05-25
 */
@Service
public class SfContractServiceImpl extends ServiceImpl<SfContractMapper, SfContract> implements ISfContractService {

    @Autowired
    SfContractMapper sfContractMapper;

    @Autowired
    private ICwPaymentPlanService iCwPaymentPlanService;


    @Override
    public PageInfo<SfContract> searchSfContracts(Integer pageNum, Integer pageSize, RequestSearchSfContractsDto requestSearchSfContractsDto) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<SfContract>(sfContractMapper.searchSfContracts(requestSearchSfContractsDto));
    }

    @Override
    public PageInfo<ResponseHouseInfoDto> searchSfListByXy(Integer pageNum, Integer pageSize, RequestSearchSfsDto requestSearchSfsDto) {
        PageHelper.startPage(pageNum,pageSize);
        return  new PageInfo<ResponseHouseInfoDto>(sfContractMapper.searchSfListByXy(requestSearchSfsDto));
    }




    /**
     * 收房合同查询
     * @author gdw
     * @param sfContract
     * @return
     */
    @Override
    public List<SfContract> selectSfContract(SfContract sfContract) {
        return getBaseMapper().selectSfContract(sfContract);
    }
    /**
     * 根据id查询合同
     * @param id
     * @return
     */
    @Override
    public SfContractModel selectSfById(Long id) {
        SfContract sfContract = getBaseMapper().selectById(id);
        //查询付款计划表
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("contract_id",id);
        queryWrapper.eq("contract_type",1);
        List<CwPaymentPlan> list = iCwPaymentPlanService.list(queryWrapper);

        SfContractModel sfContractModel = new SfContractModel();
        BeanUtils.copyProperties(sfContract,sfContractModel);
        sfContractModel.setCwPaymentPlanList(list);
        return sfContractModel;
    }
}
